package com.ddone.util.mock;

import org.apache.commons.lang3.RandomUtils;

import java.util.ArrayList;

/**
 * @author ddone
 * @date 2024/5/15-10:12
 */
public class RandomNumBuilder {
    ArrayList<Integer> numPool = new ArrayList();

    public RandomNumBuilder() {
    }

    public RandomNumBuilder(int fromNum, int toNum, Integer... weights) {
        int index = 0;

        for(int num = fromNum; num <= toNum; ++num) {
            if (num < weights.length) {
                Integer weight = weights[index++];

                for(int k = 0; k < weight; ++k) {
                    this.numPool.add(num);
                }
            }
        }

    }

    public void addNum(int num, int count) {
        for(int i = 0; i < count; ++i) {
            this.numPool.add(num);
        }

    }

    public int getNum() {
        return (Integer)this.numPool.get(RandomUtils.nextInt(0, this.numPool.size()));
    }

    public static void main(String[] args) {
        RandomNumBuilder randomNumBuilder = new RandomNumBuilder(1, 10, new Integer[]{10, 10, 10, 10, 50, 1});

        for(int i = 0; i < 100; ++i) {
            int num = randomNumBuilder.getNum();
            System.out.println(num);
        }

    }
}
